package com.ysd.entity;

import java.util.List;


import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * 模块表
 * @author CJP
 *
 */
@Entity
@Table(name="modules")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Modules {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer mid;//模块id
	private String mname;//模块name
	private Integer mparentid;//父模块编号
	private String mpath;//路径
	private Integer mweight;//权重
	@ManyToMany(fetch=FetchType.EAGER) //多对多关系
	@Cascade(value={CascadeType.SAVE_UPDATE}) //级联关系
	@JoinTable(name="rolemodules", //指定第三张中间表名称
	joinColumns={@JoinColumn(name="mid")}, //被维护方外键的对应关系
	inverseJoinColumns={@JoinColumn(name="rid")})
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Roles> rlist;//拿到与中间表连接的角色集合
	@Transient
	private List<Modules> children;//子类部分
}
